*WIC co-op eWIC twfe diff in diff analysis
*last modified: 12 May 2025
*last modified by: Charlotte Ambrozek
*this do file tabulates eventstudyindirect estimated effects of WIC EBT on SNAP and WIC authorizations and redemptions

*-------------------------------------------------------------------------------
*--- Preamble
*-------------------------------------------------------------------------------

clear all
set more off
set rmsg on

set maxvar 120000
set emptycells drop

*ssc install estout, replace

*-------------------------------------------------------------------------------
*--- Directories and Log 
*-------------------------------------------------------------------------------

local data_dir ./data/cleaned
local raw_dir ./data/raw
local out_dir ./analysis/output
local graph_dir ./analysis/output/graphs
local tab_dir ./analysis/output/tables
local log_dir ./documentation/logs
local date: display %tdYY-NN-DD date(c(current_date), "DMY")
di "`date'"
capture log close

log using `log_dir'/tables_sa`date', replace

*-------------------------------------------------------------------------------
*--- SA: 2x2 Tables
*-------------------------------------------------------------------------------

foreach data in allefsy efsy cbp {
foreach out in sa_tip_simple_`data'_never_all          sa_tip_simple_`data'_never_chain ///
               sa_tip_simple_`data'_never_indep        sa_tip_simple_nocov_`data'_never_all   ///
               sa_tip_simple_nocov_`data'_never_chain  sa_tip_simple_nocov_`data'_never_indep ///
               sa_zip_simple_`data'_never              sa_zip_simple_nocov_`data'_never {

 estimates use `out_dir'/`out'.ster
 local name = subinstr(subinstr("`out'", "_never", "", 1), "_simple", "", 1)
 di "`name'"
 estimates store `name'
}

#delimit ;
esttab sa_tip_`data'_all   sa_tip_`data'_chain 
       sa_tip_`data'_indep sa_zip_`data'
using `tab_dir'/sa_2x2table_`data'_never.tex,
stats(N, fmt(%9.0gc) labels("\\ \midrule \textit{N}")) keep(ebt) label
b(%-9.3f) se(%-9.3f) not noobs nonotes nogaps mtitles("All" "Chain" "Indep." "Redemptions") nonumbers 
style(tex) fragment replace noline starlevel("*" 0.10 "**" 0.05 "***" 0.01)
coef(ebt "WIC EBT");
#delimit cr

#delimit ;
esttab sa_tip_nocov_`data'_all   sa_tip_nocov_`data'_chain 
       sa_tip_nocov_`data'_indep sa_zip_nocov_`data'
using `tab_dir'/sa_2x2table_nocov_`data'_never.tex,
stats(N, fmt(%9.0gc) labels("\\ \midrule \textit{N}")) keep(ebt) label
b(%-9.3f) se(%-9.3f) not noobs nonotes nogaps mtitles("All" "Chain" "Indep." "Redemptions") nonumbers 
style(tex) fragment replace noline starlevel("*" 0.10 "**" 0.05 "***" 0.01)
coef(ebt "WIC EBT");
#delimit cr
estimates clear

}

*-------------------------------------------------------------------------------
*--- SA: Tip - Time varying employment - 2x2 Tables
*-------------------------------------------------------------------------------

foreach data in allefsy efsy cbp {
	
 foreach c in never last {
 	
  local i=1
	
  foreach out in sa_tip_simple_`data'_`c'_all   ///
		 sa_tip_simple_`data'_`c'_chain ///
                 sa_tip_simple_`data'_`c'_indep {
		 		       	
  estimates use `out_dir'/`out'.ster
  estimates store est`i'_`c'
  local ++i
  
  }
 }
	
 #delimit ;
 esttab est1_never est2_never est3_never
	est1_last  est2_last  est3_last
 using "`tab_dir'/sa_2x2table_tip_`data'.tex",
 stats(N, fmt(%9.0gc) labels("\\ \textit{N}")) keep(ebt) label
 b(%-9.3f) se(%-9.3f) not noobs nonotes nogaps nomtitles nonumbers 
 style(tex) fragment replace noline starlevel("*" 0.10 "**" 0.05 "***" 0.01)
 coef(ebt "WIC EBT");
 #delimit cr
 estimates clear
 
}


log close
